<?php if (!defined('THINK_PATH')) exit();?><div class="row" style="margin-bottom:10px;margin-top:10px;">
    <div class="col-xs-12">
        <button id="add" type="button" class="btn btn-block btn-info btn-sm" style="width:100px;">添加货币</button>
    </div>
</div>
<div class="row">
    <div class="col-xs-12">
        <div class="box box-danger">
            <!-- /.box-header -->
            <div class="box-body table-responsive no-padding">
                <table class="table table-striped table-hover">
                    <tbody id="row_data">
                    </tbody>
                </table>
            </div>
        </div>
        <!-- /.box -->
    </div>
</div>
<script type="text/javascript">
    //模块名称定义
    var moduleName = 'gameType';

    //加载数据
    function load() {
        showLoad();
        $.ajax({
            type : "get",
            url : 'admin/' + moduleName + '/tolist',
            dataType:"json",
            success : function(msg) {
                showData(msg);
                hideLoad();
            }
        });
    }
    load();

    //状态改变
    function changeState(obj) {
        var id = $(obj).attr('data-id');
        var state = $(obj).attr('state');
        //alert(id + ',' + state);
        showLoad();
        $.ajax({
            type : "post",
            url : 'admin/' + moduleName + '/changeState',
            dataType:"json",
            data: {
                id : id,
                state : state
            },
            success : function(msg) {
                hideLoad();
                if (msg == 1) {
                    //alert($('.badge .bg-green').html());
                    if (state == 2) {
                        $('#state_lab' + id).removeClass('bg-green');
                        $('#state_lab' + id).addClass('bg-danger');
                        $('#state_lab' + id).text('停用');
                        $(obj).removeClass('label-danger');
                        $(obj).addClass('label-success');
                        $(obj).attr('state', '1');
                        $(obj).text('启用');
                        $.scojs_message('货币已停用', $.scojs_message.TYPE_OK);
                    } else if (state == 1) {
                        $('#state_lab' + id).removeClass('bg-danger');
                        $('#state_lab' + id).addClass('bg-green');
                        $('#state_lab' + id).text('正常');
                        $(obj).removeClass('label-success');
                        $(obj).addClass('label-danger');
                        $(obj).attr('state', '2');
                        $(obj).text('停用');
                        $.scojs_message('货币已启用', $.scojs_message.TYPE_OK);
                    }
                }
            }
        });
    }

    //添加
    $('#add').on('click', function() {
        window.location.href = 'admin#' + moduleName + '/addoredit';
    });

    //编辑
    function edit_data(id) {
        window.location.href = 'admin#' + moduleName + '/addoredit/id/' + id;
    }

    //数据拼装
    function showData(msg) {
        var content = '';
        //datatable head
        content += '<tr>';
        content += '<th style="width:35px;">#</th>';
        content += '<th>货币名称/编码</th>';
        content += '<th>显示名称/规格</th>';
        content += '<th>触摸点位</th>';
        content += '<th>状态</th>';
        content += '<th style="width:150px;">操作</th>';
        content += '</tr>';

        //datatable data
        for (var i = 0; i < msg.list.length; i++) {
            content += '<tr>';
            content += '<td>' + (i+1) + '</td>';
            content += '<td>' + msg.list[i].game_name + '/<span style="font-size:11px;color:grey;">'+msg.list[i].name_code+'</span></td>';
            content += '<td>' + msg.list[i].show_name + '/<span style="font-size:11px;color:grey;">'+msg.list[i].norms+'</span></td>';
            content += '<td>' + msg.list[i].profit + '</td>';

            if (msg.list[i].state == 1)
                content += '<td><span id="state_lab' + msg.list[i].id + '" class="badge bg-green">正常</span></td>';
            else
                content += '<td><span id="state_lab' + msg.list[i].id + '" class="badge bg-danger">停用</span></td>';
            content += '<td>';
            if (msg.list[i].state == 1)
                content += '<span class="label label-danger" style="cursor:pointer;margin-right:3px;" data-id="' + msg.list[i].id + '" state="2" onclick="changeState(this);">停用</span>';
            else
                content += '<span class="label label-success" style="cursor:pointer;margin-right:3px;" data-id="' + msg.list[i].id + '" state="1" onclick="changeState(this);">启用</span>';
            content += '<span class="label label-primary" style="cursor:pointer;margin-right:3px;" onclick="edit_data(' + msg.list[i].id + ');">修改</span>';
            content += '</td>';
            content += '</tr>';
        }
        $('#row_data').html(content);
    }
</script>